import axios from 'axios'
import store from "../store/index"
import router from '../router';

// import Nprogress from "nprogress"
// import 'nprogress/nprogress.css'

const Server = axios.create({
    // baseURL: "http://39.100.7.70:81/",
    timeout: 5000,
});
Server.interceptors.request.use(function(config) {
    // console.log(config)
    // Nprogress.start()
    if (store.state.token.length > 0) {
        config.headers['Authorization'] = store.state.token;
    }
    return config
}, function(error) {
    return Promise.reject(error);
})
Server.interceptors.response.use(function(response) {
    // Nprogress.start().done()
    return response.data
}, function(error) {
    // console.log(error)
    router.push('error');
    return Promise.reject(error);
    // return error
})

export default Server